import java.util.*;

public class PokerGameIndex {
    public static void main(String[] args) {
        String[] colors = new String[]{"方块", "黑桃", "梅花", "红桃"};
        String[] numbers = new String[]{"2", "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K","A"};
        HashMap<String, Integer> Tom = new HashMap<>();
        HashMap<String, Integer> Jack = new HashMap<>();
        HashMap<String, Integer> Me = new HashMap<>();

        ArrayList<String> last = new ArrayList<String>();

        HashMap<String, Integer> pokers = new HashMap<>();
        for (int i = 0; i < colors.length; i++) {
            for (int j = 0; j < numbers.length; j++) {
                pokers.put(colors[i] + numbers[j], j);
            }
        }
        pokers.put("小王", 13);
        pokers.put("大王", 14);

        Iterator<Map.Entry<String, Integer>> pokersEntry = pokers.entrySet().iterator();
        int counter = 0;
        while (pokersEntry.hasNext()) {
            Map.Entry<String, Integer> entry = pokersEntry.next();
            if (counter < pokers.size() - 3) {
                if (counter % 3 == 0) {
                    Tom.put(entry.getKey(), entry.getValue());
                } else if (counter % 3 == 1) {
                    Jack.put(entry.getKey(), entry.getValue());

                } else if (counter % 3 == 2) {
                    Me.put(entry.getKey(), entry.getValue());
                }
            } else {
                last.add(entry.getKey());
            }
            counter++;
        }
        List<Map.Entry<String, Integer>> TomList = new ArrayList<>(Tom.entrySet());
        List<Map.Entry<String, Integer>> JackList = new ArrayList<>(Jack.entrySet());
        List<Map.Entry<String, Integer>> MeList = new ArrayList<>(Me.entrySet());

        /*
        //优化前
        Comparator c = new Comparator<Map.Entry<String, Integer>>() {
            public int compare(Map.Entry<String, Integer> o1, Map.Entry<String, Integer> o2) {
                return o1.getValue() - o2.getValue();
            }
        };
        Collections.sort(TomList, c);
        Collections.sort(JackList, c);
        Collections.sort(MeList, c);
        System.out.println("Tom的牌" + Tom.size());
        ArrayList middle = new ArrayList();
        for(Map.Entry<String, Integer> entry : TomList) {
            middle.add(entry.getKey());
        }
        System.out.println(middle);
        middle.clear();
        System.out.println("Jack的牌" + Jack.size());
        for(Map.Entry<String, Integer> entry : JackList) {
            middle.add(entry.getKey());
        }
        System.out.println(middle);
        middle.clear();
        System.out.println("Me的牌" + Me.size());
        for(Map.Entry<String, Integer> entry : MeList) {
            middle.add(entry.getKey());
        }
        System.out.println(middle);

         */
        System.out.println("Tom的牌" + Tom.size());
        sortShow(TomList);
        System.out.println("Jack的牌" + Jack.size());
        sortShow(JackList);
        System.out.println("Me的牌" + Me.size());
        sortShow(MeList);
        System.out.println("底牌"+last.size());
        System.out.println(last);

    }

    public static void sortShow(List<Map.Entry<String, Integer>> entryList) {
        ArrayList list = new ArrayList();
        entryList.sort(Comparator.comparingInt(Map.Entry::getValue));
        for(Map.Entry<String, Integer> entry : entryList) {
            list.add(entry.getKey());
        }
        System.out.println(list);
    }
}
